home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: kanze@gabi-soft.fr (J. Kanze)
- Newsgroups: comp.std.c++
- Subject: Re: constant-expression extension
- Date: 04 Mar 1996 10:33:13 PST
- Organization: GABI Software, Sarl.
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <KANZE.96Mar4120725@gabi.gabi-soft.fr>
- References: <4h775a$m4s@ugress.uib.no>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 04 Mar 1996 11:07:25 GMT
- In-Reply-To: boukanov@afrodite.fi.uib.no's message of 01 Mar 1996 09:03:14 PST
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBUAwUBMTs3jEy4NqrwXLNJAQHttgH2I8k6LxFbUszg7i++JcLpWaPqGZjAnuqC
- junGLjF+xw184klypRwKX3C71LUIEZqq7iRpJeReUW+2k4XAx0+f
- =qztA
- Originator: austern@isolde.mti.sgi.com
-
- In article <4h775a$m4s@ugress.uib.no> boukanov@afrodite.fi.uib.no (Igor
- Boukanov) writes:
-
- |> My proposal is to change definition of the
- |> "integral constant-expression"[5.19] to something like this:
-
- |> An integral constant-expression is an expression that can be calculated
- |> at the compilation phase.
-
- |> And according to this one would be able to use inline
- |> functions in constant-expressions and instead of writing:
-
- |> #define ALIGN(number, base) ((number + base - 1) / base * base)
- |> #define MAX(x, y) ((x > y) ? (x) : (y))
- |> #define GRAD_TO_RADIAN(x) (x * 3.1415926 / 180)
-
- |> char buf[ALIGN(50, sizeof(float))];
- |> char buf2[MAX(sizeof(long), sizeof(double))];
- |> const double angle = GRAD_TO_RADIAN(30);
-
- |> one can write:
-
- |> inline unsigned T align(unsigned number, unsigned base) {
- |> return ((number + base - 1) / base * base);
- |> }
-
- |> template<class T> inline T max(T x, T y){
- |> return (x > y) ? x : y;
-
- |> inline double grad_to_radian(double x){
- |> return x * 3.1415926 / 180;
- |> }
-
- |> char buf[align(50, sizeof(float))];
- |> char buf2[max(sizeof(long), sizeof(double))];
- |> const double angle = grad_to_radian(30);
-
- |> So what do you think about this?
-
- That it would be nice, but that there are two very big problems:
-
- 1. It would basically require a complete C++ interpreter in the
- compiler, and
-
- 2. It would make the notion of constant expression somewhat
- implementation dependant. Suppose my compiler implements the function
- sin as an inline invocation of a compiler built-in. Can I then use sin
- in a constant expression?
- --
- James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
- Conseils, itudes et rialisations en logiciel orienti objet --
- -- A la recherche d'une activiti dans une region francophone
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-